package services

import (
	"longmen/server/config/global"
	"longmen/server/pkg/common/helper/util"
	"longmen/server/pkg/db/mysql/db_main"
	"longmen/server/pkg/db/mysql/models/models_main"
	"longmen/server/pkg/db/redis/cache"
)

/**
@Create 2022July02 Enzo
传入一个送礼记录，计算对应的公会分成
*/
func GuildShareFromGift(gift models_main.GiftLog) {
	guildRate, plan, err := cache.GetAnchorSharePlan(gift.Anchorid)
	if err != nil {
		global.Log.Infof("[GuildShare]%s主播公会信息有误", err.Error())
	} else { //公会信息有误不给分成
		_, managerList := util.CalcCommissionListByAmount(guildRate, plan, gift.Spend)
		db_main.UpdateGuildShareFromGift(gift, *managerList)
	}
}
